﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.DBM;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class FieldBLL : IFieldBLL
    {
        private static readonly IFieldDAL DAL = DataAccess.CreateFields();
        private EmployeeTypeInfo empInfo = new EmployeeTypeInfo();
        private PositionTypeInfo posInfo = new PositionTypeInfo();
        private FieldGroupInfo groupInfo = new FieldGroupInfo();
        private ClassSpecificationInfo specInfo = new ClassSpecificationInfo();

        public IList<FieldInfo> ListFields()
        {
            return DAL.ListFields(new FieldInfo(0));
        }
        public DataSet LoadFields(string Sequence, string PositionTypes, string EmployeeTypes)
        {
            PositionTypeInfo ptInfo = new PositionTypeInfo();
            EmployeeTypeInfo etInfo = new EmployeeTypeInfo();

            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            ptInfo.Sequence = PositionTypes.Length > 0 ? Int32.Parse(PositionTypes) : 0;
            etInfo.Sequence = EmployeeTypes.Length > 0 ? Int32.Parse(EmployeeTypes) : 0;

            return DAL.LoadFields(new FieldInfo(Seq, ptInfo, etInfo));
        }
        public DataSet LoadFieldSearchText(string PositionTypes, string EmployeeTypes, string SearchText)
        {
            FieldInfo info = new FieldInfo();

            if (PositionTypes.Length > 0)
            {
                posInfo.Sequence = PositionTypes.Length > 0 ? Int32.Parse(PositionTypes) : 0;
                info.PositionTypes = posInfo;
            }
            if (EmployeeTypes.Length > 0)
            {
                empInfo.Sequence = EmployeeTypes.Length > 0 ? Int32.Parse(EmployeeTypes) : 0;
                info.EmployeeTypes = empInfo;
            }
            info.SearchText = SearchText;

            return DAL.LoadFields(info);
        }
        public DataSet LoadFieldExists(string Sequence, string PositionTypes, string EmployeeTypes)
        {
            PositionTypeInfo ptInfo = new PositionTypeInfo();
            EmployeeTypeInfo etInfo = new EmployeeTypeInfo();

            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            ptInfo.Sequence = PositionTypes.Length > 0 ? Int32.Parse(PositionTypes) : 0;
            etInfo.Sequence = EmployeeTypes.Length > 0 ? Int32.Parse(EmployeeTypes) : 0;

            return DAL.LoadFieldExists(new FieldInfo(Seq, ptInfo, etInfo));
        }
        
        public IList<FieldInfo> ListFields(string Sequence)
        {
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            return DAL.ListFields(new FieldInfo(Seq));
        }
        public IList<FieldInfo> ListFields(string PositionTypes, string EmployeeTypes)
        {
            posInfo.Sequence = PositionTypes.Length > 0 ? Int32.Parse(PositionTypes) : 0;
            empInfo.Sequence = EmployeeTypes.Length > 0 ? Int32.Parse(EmployeeTypes) : 0;
            return DAL.ListFields(new FieldInfo(0, posInfo, empInfo));
        }
        public void Insert(string Name, string NameEng, string LineName, string LineNameEng, string Remarks
            , int EmployeeTypes, int PositionTypes, int FieldGroups, int ClassSpecifications, int CreatedBy)
        {
            try
            {
                empInfo.Sequence = EmployeeTypes;
                posInfo.Sequence = PositionTypes;
                groupInfo.Sequence = FieldGroups;
                specInfo.Sequence = ClassSpecifications;

                DAL.Insert(new FieldInfo(0, Name, NameEng, LineName, LineNameEng, Remarks
                    , empInfo, posInfo, groupInfo, specInfo, CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Name, string NameEng, string LineName, string LineNameEng, string Remarks
            , int EmployeeTypes, int PositionTypes, int FieldGroups, int ClassSpecifications, int UpdatedBy)
        {
            try
            {
                empInfo.Sequence = EmployeeTypes;
                posInfo.Sequence = PositionTypes;
                groupInfo.Sequence = FieldGroups;
                specInfo.Sequence = ClassSpecifications;

                DAL.Update(new FieldInfo(Sequence, Name, NameEng, LineName, LineNameEng, Remarks
                    , empInfo, posInfo, groupInfo, specInfo, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
       
        
    }
}
